package com.fuja.fumo.ui;
import org.apache.log4j.Logger;

import com.fuja.fumo.model.Question;
import com.fuja.swf.ui.GraphGen;
import com.fuja.swf.ui.UIUtil;

import waba.ui.Window;
import waba.util.Vector;
public final  class UIResult extends GraphGen{
	private static Logger log = Logger.getLogger(UIResult.class);
	private Vector questions;
	public UIResult(Vector questions){
		super();
		this.questions = questions;
		
		double qty = questions.size();
		double error = getQtyError();
		double notAnswered = getQtyNotAnswered();
		double correct =  qty - error - notAnswered;
		
		
		double perCorrect = (correct/qty) * 100;
		double perError = (error/qty) * 100;
		double perNotAnswered = (notAnswered/qty) * 100;
		
		vec1=new Vector(new Object[]{"Correct","Wrong","Not Answered"});
		vec2=new Vector(new Object[]{
			perCorrect + "",
			perError + "",
			perNotAnswered + ""}
		);

		tipGra = TYPE_PIE; // Pie		
	}
	private int getQtyError(){
		int qty = 0;
		for (int i=0;i<questions.size();i++)
			if (((Question)questions.items[i]).isError())
				qty++;
		return qty;
	}
	private int getQtyNotAnswered(){
		int qty = 0;
		for (int i=0;i<questions.size();i++)
			if (!((Question)questions.items[i]).isAnswered())
				qty++;
		return qty;
	}
	public void onBack(){
		try {
			Window window = new UIQuestion(questions);
			UIUtil.swap(window);
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		}
		
	}
}
